package com.nowcoder.Offer.Array;

import org.junit.Test;

import java.util.Arrays;

/**
 * 输入一个正整数数组，把数组里所有数字拼接起来排成一个数，打印能拼接出的所有数字中最小的一个。
 */
public class BuildSmallerNumber {

    public String PrintMinNumber(int [] numbers) {
        String[] strs = new String[numbers.length];
        for(int i=0; i<numbers.length; i++){
            strs[i] = String.valueOf(numbers[i]);
        }

        Arrays.sort(strs, (a , b) -> (a + b).compareTo( b + a));

        StringBuilder strb = new StringBuilder();

        for(String str : strs){
            strb.append(str);
        }

        return strb.toString();
    }

    @Test
    public void test(){
        int[] arr = {3,32,321};

        System.out.println(PrintMinNumber(arr));
    }
}
